!{include file='common/iheader.htm'}
<div id="i_nav">
	<h3 class="page_title">属性组编辑!{if $attrs.name} -- !{$attrs.name}!{/if}</h3>
	<a class="button" href="/manager.php?app=attrs">属性组列表</a>
	!{if $attrs}
	<a class="button" href="/manager.php?app=attrs&act=edit">添加新组</a>
	!{/if}
	<a class="button" href="/manager.php?app=relation">关联属性管理</a>
	<a class="button" href="/manager.php?app=forms">表单管理</a>
</div>
<form method="post" id="attr_form" url="/manager.php?app=attrs">
	<div class="tabs">
		<ul class="tab_title">
			<li><a href="#base">组信息</a></li>
			!{if $attrs}
			<li><a href="#attr_item">自定义属性</a></li>
			!{/if}
		</ul>
		<div id="base">
			<div class="form_item">
				<strong>　组名称：</strong>
				<div><input class="text_input" maxlength="50" type="text" name="name" value="!{$attrs.name}"/></div>
				<p>(名称长度应该在1至50之间)</p>
			</div>
			<div class="form_item">
				<strong>　组描述：</strong>
				<div><input class="text_input" maxlength="100" type="text" name="desc" value="!{$attrs.desc}"/></div>
				<p></p>
			</div>
			<div class="form_item">
				<strong>所有者：</strong>
				<div>
					<select name="owner">
						!{html_options options=$owners selected=$attrs.owner}
					</select> 
				</div>
				<p>所有者是系统时，将不允许网站管理员修改、删除</p>
			</div>
		</div>
		!{if $attrs}
		<div id="attr_item">
			<div id="i_nav">
				<a class="button add_attr_btn" href="javascript:void(0)">添加属性</a>
			</div>
			<table class="list_table">
				<tr>
					<th>名称</th>
					<th>类型</th>
					<th>允许为空</th>
					<th>多语言</th>
					<th>操作</th>
				</tr>
				!{foreach from=$attrs.items item=item key=code name=attr}
				<tr id="item_!{$code}">
					<td>
						!{$item.name} [!{$code}]
						!{if $item.desc}<span class="ui-icon ui-icon-info" title="!{$item.desc}"></span>!{/if}
					</td>
					<td>!{$item.type_name}!{if $item.relation_name} - !{$item.relation_name} !{/if} !{if $item.trait}<span>[!{$item.trait_name}]</span>!{/if}</td>
					<td>!{if $item.required eq true}<span class="ui-icon ui-icon-close"></span>!{else}<span class="ui-icon ui-icon-check"></span>!{/if}</td>
					<td>!{if $item.mutil_lan eq true}<span class="ui-icon ui-icon-check"></span>!{else}<span class="ui-icon ui-icon-close"></span>!{/if}</td>
					<td>
						<a href="javascript:void(0)" onclick="attr_item_edit('!{$code}')"><span class="ui-icon ui-icon-pencil"></span>修改</a> 
						<a href="javascript:void(0)" onclick="del('!{$attrs._id}', '!{$code}')"><span class="ui-icon ui-icon-trash"></span>删除</a>
					</td>
				</tr>
				!{foreachelse}
				<tr><td colspan="4">暂无自定义属性</td></tr>
			!{/foreach}
			</table>
		</div>
		!{/if}
		<div class="form_item form_btn_item">
			<input type="hidden" name="id" value="!{$attrs._id|default:0}"/>
			<input class="button main" type="button" value="保存" />
		</div>
	</div>
</form>
!{if $attrs}
<div class="dialog" title="属性组条目编辑"></div>
!{/if}
<script type="text/javascript">
	function del(id, code){
		if(confirm('删除后，将可能影响使用，是否继续删除？')){
			var url = '/manager.php?app=attrs&act=item_del&id=' + id + '&code=' + code;
			$.get(url, function(data){
				var json = eval('(' + data + ')');
				alert(json.info);
				if(json.result){
					$("#item_" + code).remove();
				}
			});
		}
	}

	function attr_item_edit(code){
		var id = '!{$attrs._id|default:0}';
		var url = '/manager.php?app=attrs&act=item_edit&id=' + id;
		if(code!=null){
			url += '&code=' + code;
		}
		$(".dialog").html('正在加载，请稍候...').load(url).dialog({width:700,height:440,modal:true});
	}

	$(function(){
		$(".add_attr_btn").click(function(){
			attr_item_edit();
		});

		$("#attr_form").ajax_form({
			'submit_btn' : '.main',
			'is_alert' : false,
			'success' : function(form, data){
				window.location.href = '/manager.php?app=attrs&act=edit&id=' + data.data;
			}
		});
	});
</script>
!{include file='common/ifooter.htm'}